package com.Shoping.controller;

import com.Shoping.entity.Commodity;
import com.Shoping.service.CommodityService;
import com.Shoping.service.impl.CommodityServiceImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import java.util.List;

@WebServlet(value = "/commodity")
public class CommodityController extends BaseServlet {
    public String European(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        Integer cgId = Integer.parseInt(request.getParameter("cgId"));
        CommodityService commodityService = new CommodityServiceImpl();
        List<Commodity> list = commodityService.selectByCgId(cgId);
        return JSON.toJSONString(list);
    }

    public String Modern(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        Integer cgId = Integer.parseInt(request.getParameter("cgId"));
        CommodityService commodityService = new CommodityServiceImpl();
        List<Commodity> list = commodityService.selectByCgId(cgId);
        return JSON.toJSONString(list);
    }

    public String xiangxun(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        Integer cgId = Integer.parseInt(request.getParameter("cgId"));
        CommodityService commodityService = new CommodityServiceImpl();
        List<Commodity> list = commodityService.selectByCgId(cgId);
        return JSON.toJSONString(list);
    }

    public String selectByCmId(HttpServletRequest request,HttpServletResponse response) throws SQLException {
        Integer cmId = Integer.parseInt(request.getParameter("cmId"));
        CommodityService commodityService = new CommodityServiceImpl();
        Commodity commodity = commodityService.selectByCmId(cmId);
        return JSON.toJSONString(commodity);
    }
}
